/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    void OpInOrder(TreeNode* root,int cnt)
    {
        if(root==nullptr)return;

        OpInOrder(root->right,cnt);

        count++;
        if(count==cnt) res=root->val;

        OpInOrder(root->left,cnt);
    }

    int findTargetNode(TreeNode* root, int cnt) {
        //二叉搜索树中序遍历是递增序列，那么右根左就是递减序列
        OpInOrder(root,cnt);
        return res;
    }
private:
    int count=0;
    int res=-1;
};